<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组倒转与排序</title>
    <script>
        function fun1(){
            var str = document.getElementById("txt").value;
            var array = str.split(",");
            array.reverse();
            alert(array);
        }

        function fun2(){
            var str = document.getElementById("txt").value;
            var arr = str.split(",");
            arr.sort();
            alert(arr);
        }

        function fun3(){
            var str = document.getElementById("txt").value;
            var arr = str.split(",");
            for (var i = 0; i < arr.length; i++) {
                var flag = true;
                for(var j = 0 ; j < arr.length-i-1 ; j++){
                    if (arr[j] > arr[j+1]){
                        var temp = arr[j];
                        arr[j] = arr[j+1];
                        arr[j+1] = temp;
                        flag = false;
                    }
                }
                if (flag){
                    break;
                }
            }
            alert(arr);
        }

    </script>
</head>
<body>
    <input type="text" id="txt">
    <input type="button" value="数组倒转" onclick="fun1()">
    <input type="button" value="数组排序（文本）" onclick="fun2()">
    <input type="button" value="数组排序（大小）" onclick="fun3()">
</body>
</html>